include ../includes/head
block content
    include ../includes/header
.container-fluid
    .row
        include ../includes/slide
        .col-sm-9.col-sm-offset-3.col-md-10.col-md-offset-2.main
            h1.page-header 编辑项目
            .row.placeholders
                if(result)
                    //form.form-horizontal(role='form' action='/project/edit/#{result[0].id}' method='post')
                    form.form-horizontal(role='form')
                        div.form-group
                            label.col-sm-5.control-label(for='name') 项目名称
                            div.col-sm-3
                                input.form-control(id='name' name='name' type='text' placeholder='用户名' required value='#{result.project[0].name}')
                                input(style="display:none").form-control(id='id' required value='#{result.project[0].id}')
                        div.form-group
                            label.col-sm-5.control-label(for='owner_company') 所属公司
                            div.col-sm-3
                                input.form-control(id='owner_company' name='owner_company' type='text' placeholder='所属公司' required value='#{result.project[0].owner_company}')
                        div.form-group
                            label.col-sm-5.control-label(for='manage_company') 维护公司
                            div.col-sm-3
                                input.form-control(id='manage_company' name='manage_company' type='text' placeholder='维护公司' required value='#{result.project[0].manage_company}')
                        div.form-group
                            label.col-sm-5.control-label(for='manage_id') 项目管理员
                            div.col-sm-3
                                select.form-control(id='manage_id' name='manage_id' type='text' placeholder='项目管理员' value='#{result.project[0].owner_company}')
                                    if (result)
                                        each item in result.manager
                                            if(item)
                                                option(value='#{item.id}') #{item.username}
                        div.form-group
                            label.col-sm-5.control-label(for='comment') 项目详情
                            div.col-sm-3
                                input.form-control(id='comment' name='comment' type='text' placeholder='项目详情' required value='#{result.project[0].comment}')
                        div.form-group
                            label.col-sm-5.control-label
                            div.col-sm-1
                                //button.sub_btn.sub_left_btn#submitBtn(type='submit') 提交
                                button.sub_btn.sub_left_btn#pro_edit_btn(type='button') 提交
                            div.col-sm-1
                                a(href='/project/list')
                                    button.sub_btn.sun_right_btn(type='button') 取消
include ../includes/footer
    //AJAX调用编辑接口
script(type='text/javascript').
    $("#pro_edit_btn").click(function () {
        var project = new Object();
        var proId = $("#id").val();
        project.id = proId;
        project.name = $("#name").val();
        project.owner_company = $("#owner_company").val();
        project.manage_company = $("#manage_company").val();
        project.manage_id = $("#manage_id").val();
        project.comment = $("#comment").val();
        $.ajax({
            method: "POST",
            url: '/project/edit/' + proId,
            data: project,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    Tip.alert("edit", "project", "success");
                } else {
                    Tip.alert("edit", "project", "error");
                }

            },
            error: function (data) {
                Tip.alert("edit", "project", "error");
            }
        });

    });